<?php
    
//require_once '../../../jqSuitePHP_4_1_2_2/jq-config.php';

// include the jqGrid Class
require_once 'jq-config1.php';

require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";   
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");

//echo ABSPATH;


// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query

//$grid->SelectCommand = "SELECT idPaciente, Nombre, Apellido, TipoDoc, NumDoc FROM paciente " ;


/*
echo $grid->SelectCommand= "SELECT historiaclinica.idHistoriaClinica,paciente_x_historiaclinica.idPaciente, paciente_x_historiaclinica.FechaHistoriaClinica 
FROM historiaclinica, paciente_x_historiaclinica WHERE paciente_x_historiaclinica.idPaciente= '".$_GET['Pac']."'
AND paciente_x_historiaclinica.idHistoriaClinica=historiaclinica.idHistoriaClinica ";
*/

$grid->SelectCommand= "SELECT historiaclinica.idHistoriaClinica,paciente_x_historiaclinica.idPaciente, paciente_x_historiaclinica.FechaHistoriaClinica 
FROM historiaclinica, paciente_x_historiaclinica WHERE paciente_x_historiaclinica.idPaciente= 1
AND paciente_x_historiaclinica.idHistoriaClinica=historiaclinica.idHistoriaClinica ";


//echo $grid->SelectCommand ;
// Set the table to where you update the data
//
//$grid->table = 'paciente';


// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model

$grid->setColModel();

/*
$thdirH=getcwd();
$thdirH=$thdirH."\gridpac.php";    
$grid->setUrl($thdirH);
*/

$grid->setUrl("gridpac.php");
//$grid->setUrl("DatosPacienteActual/HCPaciente/HCPacienteLectora/gridpac.php");

//echo $thdirH;
// Set the url from where we obtain the data
// Set the url from where we obtain the data

/////     

// Set some grid options
$grid->setGridOptions(array(
        "width"=>600,
        "height"=>80,  
    "rowNum"=>10,
    "rowList"=>array(10,20,30),
    "sortname"=>"idPaciente"
));


$grid->setColProperty('idPaciente', array("label"=>"ID Paciente", "width"=>100));
$grid->setColProperty('idHistoriaClinica', array("label"=>"ID HCD", "width"=>100));
$grid->setColProperty('FechaHistoriaClinica', array("label"=>"Fecha HCD", "width"=>100));

/*
$selectorder = <<<Paciente
function(rowid, selected)
{
    if(rowid != null) {
        jQuery("#detail1").jqGrid('setGridParam',{postData:{idPaciente:rowid}});
        jQuery("#detail1").trigger("reloadGrid");
    }
}
Paciente;

$grid->setGridEvent('onSelectRow', $selectorder);

*/

$grid->toolbarfilter = true; 
// Enable navigator

?>


<?
$pepe1 = <<<PEPE1
 
jQuery("#getselectedL").click(function(){
    var selrL = jQuery('#grid').jqGrid('getGridParam','selrow');
    
    if(selrL) window.location.href = "http://healthsolutions.com.ar/DatosPacienteActual/HCPaciente/HCPacienteLectora/HCPacienteLectora.php?Pac="+Pac1+"&PXHC="+selrL;
  //  if(selrL) window.location.href = "http://healthsolutions.com.ar/DatosPacienteActual/HCPaciente/HCPacienteLectora/HCPacienteLectora.php?Pac=1"+Pac1"&PXHC="+selrL;

//    if(selrL) window.location.href = "http://localhost/DatosPacienteActual/HCPaciente/HCPacienteLectora/HCPacienteLectora.php?PXHC="+selrL;
  

    if(selrL) {
    //alert(selrL);
    }
    else alert("No selected row");
    return false;
});

PEPE1;



$grid->setJSCode($pepe1); 



$grid->navigator = true;
// Enable only editing
//$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));

$grid->setNavOptions('navigator', array("excel"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>true, "search"=>true));

// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);



// we set the select for ship city 

//$grid->setSelect("ShipCity", "SELECT DISTINCT ShipCity, ShipCity AS CityName FROM orders ORDER BY 2", false, false, true, array(""=>"All"))

$conn = null; 


?> 
